#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <unistd.h>
#include <event.h>
#include <signal.h>


void signal_cb(int fd, short event, void *arg)
{
	printf("SIGINT was call\n");
}

void time_cb(int fd, short event, void *arg)
{
	printf("time out\n");
}


int main()
{
	struct event_base *base = event_init(); //base为Libevent的一个实例,对base进行初始化
	
	//创建信号事件
	struct event *signal_event = evsignal_new(base, SIGINT, signal_cb, NULL);
	event_add(signal_event, NULL); //将事件注册到Libevent中

	//创建定时事件
	struct timeval tm = {1, 0}; //定时时间
	struct event *time_event = event_new(base, -1, EV_READ|EV_PERSIST, time_cb, NULL);
	event_add(time_event, &tm); //将事件注册到Libevent中

	//执行事件循环,检测就绪事件
	event_base_dispatch(base);

	//事件循环结束,释放资源
	event_free(signal_event);
	event_free(time_event);
	event_base_free(base);

	exit(0);
}

